package com.hiof.activities;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import com.hiof.Configuration;
import com.hiof.R;
import com.hiof.servercommunication.auth.LoginTask;
import com.hiof.servercommunication.push.beans.LoginPacket;
import com.hiof.settings.SettingManager;
import com.hiof.utility.Utility;

/**
 * Created by IntelliJ IDEA.
 * User: manish
 * Date: 3/22/12
 * Time: 9:53 PM
 * To change this template use File | Settings | File Templates.
 */
public class SplashScreenActivity extends Activity {
//    ProgressDialog autoLoginProgressDialog;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_screen);
        setup();
    }

    /**
     * Helper method to start the animation on the splash screen
     */

    private void setup(){
        Configuration.getInstance().setCurrentContext(this);
        Configuration.getInstance().prepareConfiguration(this.getApplicationContext());
        boolean autoLogin = SettingManager.getInstance().getAutoLogin();
        String username = SettingManager.getInstance().getUsername();
        String password = SettingManager.getInstance().getPassword();
        if (autoLogin && username != "" && password != "") {
            Utility.debug(this.getClass().toString(), "Auto Login");
            LoginTask loginTask = new LoginTask();
            loginTask.execute(new LoginPacket(username, password));
        } else{
            Utility.debug(this.getClass().toString(), "Blank credentials or Auto Login Disabled");
            Intent intent = new Intent();
            intent.setClass(this, LoginActivity.class);
            startActivity(intent);
            finish();
        }
    }
}
